package com.peerialism.natcracker.discovery.jstun.attribute;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;

import com.peerialism.natcracker.discovery.jstun.utils.UtilityException;

public class ChangeResponse {
	public InetAddress localAddress;
	public int localPort;
	public InetSocketAddress mappedAddress;
	public InetSocketAddress changedAddress;

	boolean noResponse = false;

	public ChangeResponse(boolean noResponse) {
		this.noResponse = noResponse;
	}

	public ChangeResponse(ChangedAddress changedAddress, InetAddress localAddress, int localPort, MappedAddress mappedAddress) {
		try {
			this.changedAddress = new InetSocketAddress(changedAddress.getAddress().getInetAddress(), changedAddress.getPort());
			this.mappedAddress = new InetSocketAddress(mappedAddress.getAddress().getInetAddress(), mappedAddress.getPort());
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (UtilityException e) {
			e.printStackTrace();
		}
		this.localAddress = localAddress;
		this.localPort = localPort;
	}

	public InetSocketAddress getMappedAddress() {
		return mappedAddress;
	}

	public int getMappedPort() {
		return mappedAddress.getPort();
	}

	public InetSocketAddress getChangedAddress() {
		return changedAddress;
	}

	public int getChangedPort() {
		return changedAddress.getPort();
	}

	public void setNoResponse() {
		this.noResponse = true;
	}

	public boolean isNoResponse() {
		return noResponse;
	}

	@Override
	public String toString() {
		return "mapped:" + this.mappedAddress;
	}
}